package com.liyao.storehouse.service.impl;

import com.liyao.storehouse.dao.intelligenceDao;
import com.liyao.storehouse.pojo.intelligence.*;
import com.liyao.storehouse.service.intelligenceService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class intelligenceServiceImpl implements intelligenceService {
    @Resource
    intelligenceDao dao;

    @Override
    public JSONObject getToolReceiveLogList(int page, int limit) {
        JSONObject js=new JSONObject();
        JSONArray arr=new JSONArray();
        List<receiveLog> list=dao.getToolReceiveLogList((page-1)*limit,limit);
        for(receiveLog c:list){
            js.put("id",c.getId());
            js.put("username",c.getUsername());
            js.put("deviceId",c.getDeviceId());
            js.put("location",c.getLocation());
            js.put("partDes",c.getPartDes());
            js.put("quantity",c.getQuantity());
            js.put("createdAt",c.getCreatedAt());
            arr.add(js);
        }
        int x= dao.getToolReceiveLogListCount();
        js.put("count", x);
        js.put("code",0);
        js.put("data",arr);
        return js;
    }

    @Override
    public List<receiveLogExcel> outGravityCabinetToolExcel(String partDes, String location, String userName) {
        List<receiveLogExcel> list=dao.outGravityCabinetToolExcel(partDes,location,userName);
        return list;
    }

    @Override
    public JSONObject SearchToolReceiveLogList(int page, int limit, String partDes, String location, String userName) {
        JSONObject js=new JSONObject();
        JSONArray arr=new JSONArray();
        List<receiveLog> list=dao.SearchToolReceiveLogList((page-1)*limit,limit,partDes,location,userName);
        for(receiveLog c:list){
            js.put("id",c.getId());
            js.put("username",c.getUsername());
            js.put("deviceId",c.getDeviceId());
            js.put("location",c.getLocation());
            js.put("partDes",c.getPartDes());
            js.put("quantity",c.getQuantity());
            js.put("createdAt",c.getCreatedAt());
            arr.add(js);
        }
        int x= dao.SearchToolReceiveLogListCount(partDes,location,userName);
        js.put("count", x);
        js.put("code",0);
        js.put("data",arr);
        return js;
    }

    @Override
    public JSONObject getInOutLogList(int page, int limit) {
        JSONObject js=new JSONObject();
        JSONArray arr=new JSONArray();
        List<inOutLog> list=dao.getInOutLogList((page-1)*limit,limit);
        for(inOutLog c:list){
            js.put("id",c.getId());
            js.put("username",c.getUsername());
            js.put("deviceId",c.getDeviceId());
            js.put("location",c.getLocation());
            js.put("onShelfText",c.getOnShelf() == 0 ? "下架" : "上架");
            js.put("partDes",c.getPartDes());
            js.put("createdAt",c.getCreatedAt());
            arr.add(js);
        }
        int x= dao.getInOutLogListCount();
        js.put("count", x);
        js.put("code",0);
        js.put("data",arr);
        return js;
    }

    @Override
    public List<inOutLogExcel> outInOutLogExcel(String partDes, String location, String userName, String onShelf) {
        List<inOutLogExcel> list=dao.outInOutLogExcel(partDes,location,userName,onShelf);
        return list;
    }

    @Override
    public JSONObject SearchInOutLogList(int page, int limit, String partDes, String location, String userName, String onShelf) {
        JSONObject js=new JSONObject();
        JSONArray arr=new JSONArray();
        List<inOutLog> list=dao.SearchInOutLogList((page-1)*limit,limit,partDes,location,userName,onShelf);
        for(inOutLog c:list){
            js.put("id",c.getId());
            js.put("username",c.getUsername());
            js.put("deviceId",c.getDeviceId());
            js.put("location",c.getLocation());
            js.put("onShelfText",c.getOnShelf() == 0 ? "下架" : "上架");
            js.put("partDes",c.getPartDes());
            js.put("createdAt",c.getCreatedAt());
            arr.add(js);
        }
        int x= dao.SearchInOutLogListCount(partDes,location,userName,onShelf);
        js.put("count", x);
        js.put("code",0);
        js.put("data",arr);
        return js;
    }

    @Override
    public JSONObject getGoodsList(int page, int limit) {
        JSONObject js=new JSONObject();
        JSONArray arr=new JSONArray();
        List<goodsList> list=dao.getGoodsList((page-1)*limit,limit);
        for(goodsList c:list){
            js.put("id",c.getId());
            js.put("deviceId",c.getDeviceId());
            js.put("partNo",c.getPartNo());
            js.put("partDes",c.getPartDes());
            js.put("num",c.getNum());
            js.put("location",c.getLocation());
            js.put("createdAt",c.getCreatedAt());
            arr.add(js);
        }
        int x= dao.getGoodsListCount();
        js.put("count", x);
        js.put("code",0);
        js.put("data",arr);
        return js;
    }

    @Override
    public List<goodsListExcel> outGoodsExcel(String partDes, String location, String partNo) {
        List<goodsListExcel> list=dao.outGoodsExcel(partDes,location,partNo);
        return list;
    }

    @Override
    public JSONObject SearchGoodsList(int page, int limit, String partDes, String location, String partNo) {
        JSONObject js=new JSONObject();
        JSONArray arr=new JSONArray();
        List<goodsList> list=dao.SearchGoodsList((page-1)*limit,limit,partDes,location,partNo);
        for(goodsList c:list){
            js.put("id",c.getId());
            js.put("deviceId",c.getDeviceId());
            js.put("partNo",c.getPartNo());
            js.put("partDes",c.getPartDes());
            js.put("num",c.getNum());
            js.put("location",c.getLocation());
            js.put("createdAt",c.getCreatedAt());
            arr.add(js);
        }
        int x= dao.SearchGoodsListCount(partDes,location,partNo);
        js.put("count", x);
        js.put("code",0);
        js.put("data",arr);
        return js;
    }
}
